package com.zhuangjie.coupon.enums;

/**
 * 优惠券产品状态
 *
 * @author zhuangjie
 * @date 2024/02/29
 */
public enum CouponProductState {
    WAITING_PAYMENT((byte)0, "待支付"),
    PURCHASED((byte)1, "已购买"),
    UNUSED_RETURNED((byte)-1, "未使用退购"),
    /**
     * 该状态可能不使用，优惠卷订单，不下单会被删除掉
     */
    CANCELLED((byte)-2, "已取消");

    private final byte code;
    private final String description;

    CouponProductState(byte code, String description) {
        this.code = code;
        this.description = description;
    }

    public byte getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    //Optional: A method can be added that retrieves the status base on code.
    public static CouponProductState of(int code) {
        for (CouponProductState state : CouponProductState.values()) {
            if (state.code == code) {
                return state;
            }
        }
        throw new IllegalArgumentException("Invalid state code");
    }
}